<?php
/**
 * My new Zend Framework project
 * 
 * @author  
 * @version 
 */

error_reporting(E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR|E_USER_ERROR);
ini_set('display_errors', 1);
date_default_timezone_set('America/Caracas');
$directorio = '.' . PATH_SEPARATOR . './library' 
	. PATH_SEPARATOR . './application/models/' 
	. PATH_SEPARATOR . '/usr/share/php/Smarty/' 
	. PATH_SEPARATOR . '/usr/share/php/smarty/' 
	. PATH_SEPARATOR . get_include_path();
//die($directorio);
set_include_path($directorio);
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
/**
 * Setup controller
 */
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('./application/controllers');
$controller->setBaseUrl('/rnaasv/');
$controller->throwExceptions(true); // should be turned off in production server 
//Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));

//Zend_Loader::loadClass('Naneau_View_Smarty');
//Zend_Loader::loadClass('Zend_Auth');
//Zend_Loader::loadClass('Zend_Config_Ini');
//Zend_Loader::loadClass('Zend_Controller_Action_Helper_ViewRenderer');
//Zend_Loader::loadClass('Zend_Db');
//Zend_Loader::loadClass('Zend_Db_Table');
//Zend_Loader::loadClass('Zend_Registry');


// load configuration
$config = new Zend_Config_Ini('./application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);

// setup database
$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
$registry->set('db', $db);

try {

	$fileAcl = file_get_contents('./application/acl.js');
	$rscs = Rnaasv_ObjectParser::getInstance()->jsonArray2MenuResourceArray($fileAcl);
	
	// Create auth object
	$auth = Zend_Auth::getInstance();
	
	// Create acl object
	$acl = new Rnaasv_Acl($rscs); // see 
	
	$registry->set('rscs', $rscs);
	$registry->set('acl', $acl);
	
	$controller->registerPlugin(new Rnaasv_AclControllerPlugin($auth, $acl));
	
	//smarty config
	/**
	 * Naneau_View_Smarty
	 */
	$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
	$viewRenderer->setView(new Naneau_View_Smarty(
		array('compileDir' => '/tmp')
	//replace COMPILE_DIR with a  directory your webserver has write access to
	));
	//make viewRenderer use Naneau_View_Smarty
	
	$viewRenderer->setViewSuffix('tpl');
	//make it search for .tpl files
	
	Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
	//add it to the action helper broker
	/*
	*/
	
	// run!
    $controller->dispatch();
} catch(Exception $e) {
    echo nl2br($e->__toString());
}
//echo "<!--\r\n ";
//var_dump($rscs) ;
//echo " \r\n-->";